package studio7i.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import studio7i.excepcion.DAOExcepcion;
import studio7i.modelo.Servicio;
import studio7i.negocio.ServicioNegocio;

/**
 * Servlet implementation class RegistrarServicio
 */
@WebServlet("/RegistrarServicio")
public class RegistrarServicio extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarServicio() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String nombre=request.getParameter("nombre");
		String caracteristicas=request.getParameter("caracteristicas");
		double precio=Double.parseDouble(request.getParameter("precio"));	
		
		ServicioNegocio ser = new ServicioNegocio();
		Servicio serTest;
		try {
			serTest = ser.insertarServicio(nombre,caracteristicas,precio);
			PrintWriter out = response.getWriter();
	        out.println("<html>");
	        out.println("<center>");
	        out.println("Registro Exitoso<p>");
	        out.println("Nombre: "+serTest.getNombre()+"<br>");
	        out.println("Caracteristicas: "+serTest.getCaracteristicas()+"<br>");
	        out.println("Precio: "+serTest.getPrecio().toString()+"<br>");
	        out.println("</center>");
	        out.println("</html>");
	        out.close();
		} catch (DAOExcepcion e) {
			e.printStackTrace();
		}
	}

}
